<template>
<div>
     <el-container class="wrap">
      <el-aside width="200px">
        <!-- 
          default-active    默认激活的菜单
          background-color   背景颜色
          text-color          文字颜色
          active-text-color   菜单激活时的文字颜色
          unique-opened       是否只保持一个子菜单打开
          router              是否使用路由模式
         -->
        <el-menu
          default-active="/"
          class="el-menu-vertical-demo"
          background-color="rgb(253, 99, 68)"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-circle-check"></i>
            <span slot="title">首页</span>
          </el-menu-item>


        <div v-for="item in  userInfo.menus" :key="item.id">
              <!-- 目录 -->
                <el-submenu :index="item.id+''" v-if="item.children">
                  <template slot="title">
                    <i class="el-icon-setting"></i>
                    <span>{{item.title}}</span>
                  </template>
                  <el-menu-item v-for="i in item.children" :key="i.id" :index="i.url">{{i.title}}</el-menu-item>
                </el-submenu> 
              <!-- 菜单 -->
                <el-submenu :index="item.url" v-else>{{item.title}}</el-submenu>
        </div>

        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
            <div>
              <p>用户名：{{userInfo.username}}</p>
              <el-button type="primse" @click="out()">退出</el-button>
      </div>
        </el-header>
        <el-main>
          <!-- 面包屑 -->
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{$route.meta.title}}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</div>
</template>
<script>
import {mapGetters,mapActions} from 'vuex';
import { sucessAlert } from '../../utils/alert';
export default {
props: [],
components: {},
data() {
return {};
},
computed: {
...mapGetters({
  userInfo:"user"
}),
},
methods: {
...mapActions({
  asyncUser:"asyncUser"
}),
  out(){
    this.asyncUser({}),
    sucessAlert("退出成功")
    this.$router.push("/login")
  }
},
mounted() {},
};
</script>
<style scoped lang="less">
@import url("../../less/index.less");
.wrap {
  width: 100vw;
  height: 100vh;
}
.el-header {
  background-color: @color3;
}

.el-aside {
  background-color: @color1;
}

.el-main {
  background-color: @color5;
}
</style>